package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.Orders;
import com.sky.result.Result;
import com.sky.service.UserOrderService;
import com.sky.vo.OrderDetailVO;
import com.sky.vo.OrderSearchPageVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.UserOrderSearchPageVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/order")
@RequiredArgsConstructor
@Slf4j
public class UserOrderController {

    private final UserOrderService userOrderService;

    @PostMapping("/submit")
    public Result<?> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        OrderSubmitVO orderSubmitVO = userOrderService.submit(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    @GetMapping("/historyOrders")
    public Result<?> UserHistoryOrders(OrdersPageQueryDTO ordersPageQueryDTO){
        UserOrderSearchPageVO userOrderSearchPageVO = userOrderService.historyOrders(ordersPageQueryDTO);
        return Result.success(userOrderSearchPageVO);
    }

    @GetMapping("/orderDetail/{id}")
    public Result<?> userOrderDetail(@PathVariable Long id){
        Orders orders = userOrderService.selectUserOrderDetailById(id);
        return Result.success(orders);
    }

    @PutMapping("/cancel/{id}")
    public Result<?> cancel(@PathVariable Long id){
        userOrderService.cancelOrderById(id);
        return Result.success();
    }

    @PostMapping("/repetition/{id}")
    public Result<?> repetition(@PathVariable Long id){
        userOrderService.repetitionById(id);
        return Result.success();
    }

    @GetMapping("/paySuccess/{number}")
    public Result<?> paySuccess(@PathVariable String number){
        userOrderService.paySuccess(number);
        return Result.success();
    }

    @GetMapping("/reminder/{orderId}")
    public Result<?> reminder(@PathVariable Long orderId){
        userOrderService.reminder(orderId);
        return Result.success();
    }
}
